#include "hbond.h"
#include "../bulk_storage/bulk_storage.h"

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>

int main()
{

  char line1[83];
  char line2[83];
  struct hbond * hb = 0;
  struct store * hbstore = store_open_cached("hb_store","hb_store.fat",
					     sizeof(struct hbond),(off_t)100,(off_t)2000);
  int i = 0;

  printf("%ld\n", (intptr_t)sizeof(struct hbond));

  while ((fgets(line1, 82, stdin) != NULL) && (fgets(line2, 82, stdin) != NULL))
    {
      i = store_new (hbstore);
      hb = store_read(hbstore, i);

      strncpy(hb->donorname, &(line1[5]), 3);

      //line1[15] = '\0';
      //hb->donornumber = atoi(&(line1[12]));
      strncpy(hb->donornumber, &(line1[12]),4);

      hb->donorchain = line1[18];

      strncpy(hb->donoratom, &line1[23], 3);

      strncpy(hb->acceptorname, &line1[35],3);

      //line1[46] = '\0';
      //hb->acceptornumber = atoi(&(line1[43]));
      strncpy(hb->donornumber, &(line1[42]),4);

      hb->acceptorchain = line1[48];

      strncpy(hb->acceptorname, &line1[53],3);

      line1[77] = '\0';
      hb->vaule = atof(&(line1[72]));

      line2[13]= '\0';
      hb->distance = atof(&(line2[8]));
    }

    store_write( hbstore, i);
    store_release( hbstore, i);
    printf("name1 = %c%c%c, number = %c%c%c%c, chain1= %c, name2= %c%c%c, number = %c%c%c%c, chain2= %c,val = %f, dis = %f\n",hb->donorname[0],hb->donorname[1],hb->donorname[2], hb->donornumber[0],hb->donornumber[1],hb->donornumber[2],hb->donornumber[3], hb->donorchain, hb->acceptorname[0], hb->acceptorname[1], hb->acceptorname[2], hb->acceptornumber[0],hb->acceptornumber[1],hb->acceptornumber[2],hb->acceptornumber[3], hb->acceptorchain,hb->vaule, hb->distance);

    store_close(hbstore);
    return 0;
}





